package com.bailong.administrator.ausedcar.ui.detail;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bailong.administrator.ausedcar.R;
import com.bailong.administrator.ausedcar.bean.DetailBean;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by Administrator on 2016/9/8.
 */
public class DetailAdapter extends PagerAdapter {
    private Context context;
    private List<DetailBean.DataBean.PicListBean> totallist;

    public DetailAdapter(Context context, List<DetailBean.DataBean.PicListBean> totallist) {
        this.context = context;
        this.totallist = totallist;
    }

    @Override
    public int getCount() {
        return totallist.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.detail_viewpager_item, null);
        ImageView detail_viewpager_item_iv = (ImageView) view.findViewById(R.id.detail_viewpager_item_iv);
        Glide.with(context).load(totallist.get(position)).into(detail_viewpager_item_iv);
        container.addView(detail_viewpager_item_iv);
        return detail_viewpager_item_iv;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        container.removeView((View) object);
    }
    public void reloadData(List list) {

        totallist.addAll(list) ;
        notifyDataSetChanged();
    }
}
